local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

function scene:updateLevelCallback()
return function(delta)

end
end

function scene:createGameObjects()
   --Gas Effect
   local x,y = X*0.5,Y*0.9

   textField = display.newText({text='Gas Effect "100% A manija"',x=x,y=y})
   timer.performWithDelay(
      250,
      function()
         self:pushGas(x,Y*0.5)
      end,
      20
   )

   index = 1
   vent = CBE.newVent({preset="aurora"})
   effects = {"aurora","burn","circles","embers","evil","fluid","fountain","hyperspace","rain","smoke","snow","sparks","steam","water","waterfall","out","rotate"}
   timer.performWithDelay(
      5000,
      function()
         timer.performWithDelay(
            3000,
            function()
               nextEffect()
            end

         )
      end
   )
   Runtime:addEventListener(
      'tap',function(event)
         if event.x > halfX then
            nextEffect()
         else
            prevEffect()
         end
      end
   )
end

function nextEffect()
   local presetName = effects[index]
   textField.text = presetName
   vent.stop()
   vent = CBE.newVent({preset=presetName})
   vent:start()

   index = index + 1
   if index == #effects + 1 then
      index = 1
   end
end

function prevEffect()
   local presetName = effects[index]
   textField.text = presetName
   vent.stop()
   vent = CBE.newVent({preset=presetName})
   vent:start()

   index = index - 1
   if index == 0 then
      index = #effects
   end
end

function scene:pushGas(x,y)
   local gas = display.newImage(self.view,'resources/sprites/gas_effect.png',x,y)
   gas:scale(0.01,0.01)
   gas:rotate(math.random(1,360))
   gas.alpha=0.8

   transition.to(
      gas,
      {
         time=3000,
         xScale=0.1,
         yScale=0.1,
         alpha=0,
         onComplete=function()
            DisplayObjectUtils.safeRemove(gas)
         end
      }
   )
end

--Methods
function scene:createScene(event)
   logger:gameEvent("Create TestingEffects Scene")
   storyboard.removeAll()

   scene:createGameObjects()
end
function scene:enterScene(event)
   logger:gameEvent("Enter TestingEffects Scene")



   GameController.getInstance().addCallback(scene:updateLevelCallback(), 'mainLoop')
   GameController.getInstance():beginGame()
end

function scene:exitScene(event)
   logger:gameEvent("exit TestingEffects Scene")
   GameController.getInstance().clearAllCallbacks()
   GameController.getInstance():stop()
end

function scene:destroyScene(event)
   logger:gameEvent("destroy TestingEffects Scene")
   GameController.getInstance().clearAllCallbacks()
   GameController.getInstance():stop()
end

scene:addEventListener("createScene",scene)
scene:addEventListener("enterScene",scene)
scene:addEventListener("exitScene",scene)
scene:addEventListener("destroyScene", scene)

return scene



